package com.jlastu.znb.dfh;


import android.os.Bundle;
import android.view.View;
import android.widget.AdapterView;
import android.widget.ListView;

import androidx.appcompat.app.AppCompatActivity;
import com.jlastu.znb.adapter.dfhAdapter;
import com.jlastu.znb.R;

public class dfhActivity extends AppCompatActivity {
    private dfhAdapter dfhAdapter;
    private ListView dfhListView;
    private com.jlastu.znb.dfh.dfhManager dfhManager;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.dfh);

        dfhManager = new dfhManager(this);
        dfhListView = findViewById(R.id.dfh_list_view);
        dfhAdapter = new dfhAdapter(this, dfhManager.getdfhItems());
        dfhListView.setAdapter(dfhAdapter);

        // 设置待收货列表项点击事件，用于删除操作
        dfhListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
            @Override
            public void onItemClick(AdapterView<?> parent, View view, int position, long id) {
                dfhItem itemToRemove = dfhAdapter.getItem(position);
                dfhManager.removeFromdfh(itemToRemove.getId());
                dfhAdapter.remove(itemToRemove);
                dfhAdapter.notifyDataSetChanged();
            }
        });
    }
}